﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public partial class ShopQuestioner
    {
        partial void ShopQuestionerGroup_Changed()
        {
            if (ShopQuestionerAnswers.Count() != 0)
            {
                foreach (ShopQuestionerAnswer item in this.ShopQuestionerAnswers)
                {
                    this.ShopQuestionerAnswers.Remove(item);
                }
            }
            if (ShopQuestionerGroup != null && this.ShopQuestionerAnswers.Count() == 0)
            {
                foreach (var question in this.DataWorkspace.ApplicationData.QuestionerGroups.Where(qg => qg.Id == ShopQuestionerGroup.Id).SingleOrDefault().Questioners)
                {
                    ShopQuestionerAnswer sqa = this.ShopQuestionerAnswers.AddNew();
                    sqa.Questioner = question;
                }
            }

        }

        partial void ShopQuestionerValue_Compute(ref decimal result)
        {
            result = 0;
            foreach (var item in this.ShopQuestionerAnswers)
	        {
                if (item.QuestionerChoice != null)
                    result += item.QuestionerChoice.QuestionerChoiceValue;
            }
            
        }
    }
}
